import { writeFileSync } from 'fs';

// 定义可能的值
const locations = [
'榕园食堂', '荔园食堂', '菜鸟驿站', '若海食堂',
'图书馆', '槿园食堂', '华夏门外卖架'
];

const deliveryLocations = [
'榕园食堂', '荔园食堂', '菜鸟驿站', '若海食堂', 
'图书馆', '槿园食堂', '华夏门外卖架'
];

const status = ['PUBLISHED', 'PENDING', 'ARGUE', 'COMPLETED', 'CANCELLED'];
const types = [1, 2]; // 1: 快递, 2: 外卖
const methods = ['自提', '代取', '定点存放'];
const sizes = [1, 2, 3]; // 1: 小, 2: 中, 3: 大

// 随机生成一个订单
function generateOrder(id) {
  // 生成更合理的时间范围
  const now = new Date();
  const currentDate = new Date(
    now.getFullYear(),
    now.getMonth(),
    now.getDate(),
    Math.floor(Math.random() * 24),           // 随机小时
    Math.floor(Math.random() * 60)            // 随机分钟
  );
  
  // 限制时间设置为当前时间后的1-7天
  const limitTime = new Date(currentDate);
  limitTime.setDate(limitTime.getDate() + Math.floor(Math.random() * 7) + 1);
  limitTime.setHours(Math.floor(Math.random() * 24));
  limitTime.setMinutes(Math.floor(Math.random() * 60));
  
  // 完成时间可能为空或在限制时间之前
  const completedAt = Math.random() > 0.5 ? new Date(limitTime.getTime() - Math.random() * 24 * 60 * 60 * 1000) : null;

  return {
    id: id,  // 改为 id
    s_uid: Math.floor(Math.random() * 100) + 1, // 假设用户ID从1-100
    r_uid: Math.random() > 0.3 ? Math.floor(Math.random() * 100) + 1 : null,
    pickup_type: types[Math.floor(Math.random() * types.length)],
    pickup_method: methods[Math.floor(Math.random() * methods.length)],
    pickup_address: locations[Math.floor(Math.random() * locations.length)],
    delivery_address: deliveryLocations[Math.floor(Math.random() * deliveryLocations.length)],
    size: sizes[Math.floor(Math.random() * sizes.length)],
    limit_time: limitTime.toISOString(),
    phone_number: `1${Math.floor(Math.random() * 100000000).toString().padStart(8, '0')}`,
    remarks: ['请轻拿轻放', '易碎物品', '加急件', '常规快递'][Math.floor(Math.random() * 4)],
    detail: `取件码：${Math.floor(Math.random() * 10000)}`,
    total_amount: (Math.floor(Math.random() * 1000) / 100 + 3).toFixed(2),
    status: status[Math.floor(Math.random() * status.length)],
    created_at: currentDate.toISOString(),
    completed_at: completedAt?.toISOString() || null,
    star: Math.floor(Math.random() * 5) + 1,
    img: Math.random() > 0.5 ? 'order_image.jpg' : null
  };
}

// 生成指定数量的订单数据
function generateOrders(count) {
  const orders = {
    order: Array.from({length: count}, (_, i) => generateOrder(i + 1))
  };
  
  try {
    const filePath = 'E:/frontend/proxy-platform---tentative/data/orders.json';
    writeFileSync(
      filePath,
      JSON.stringify(orders, null, 2),
      'utf8'
    );
    
    console.log(`Successfully generated ${count} orders to ${filePath}`);
  } catch (error) {
    console.error('Error generating orders:', error);
  }
}

// 生成100条订单数据
generateOrders(100);
